package com.bcn.login_mybatisplus_demo.diary.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.bcn.login_mybatisplus_demo.diary.domain.TAppDiary;
import com.bcn.login_mybatisplus_demo.diary.mapper.TAppDiaryMapper;
import com.bcn.login_mybatisplus_demo.diary.service.ITAppDiaryService;
import com.bcn.login_mybatisplus_demo.interceptor.AuthStorage;
import com.bcn.login_mybatisplus_demo.util.Convert;
import com.bcn.login_mybatisplus_demo.util.DateUtils;
import com.bcn.login_mybatisplus_demo.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 心岛日志Service业务层处理
 * 
 * @author administrator
 * @date 2025-03-11
 */
@Service
public class TAppDiaryServiceImpl implements ITAppDiaryService
{
    @Autowired
    private TAppDiaryMapper tAppDiaryMapper;

    /**
     * 查询心岛日志
     * 
     * @param diaryId 心岛日志ID
     * @return 心岛日志
     */
    @Override
    public TAppDiary selectTAppDiaryById(Integer diaryId)
    {
        return tAppDiaryMapper.selectTAppDiaryById(diaryId);
    }

    /**
     * 查询心岛日志列表
     * 
     * @param tAppDiary 心岛日志
     * @return 心岛日志
     */
    @Override
    public List<TAppDiary> selectTAppDiaryList(TAppDiary tAppDiary)
    {

        tAppDiary.setUserId(AuthStorage.getUser().getId());
        return tAppDiaryMapper.selectTAppDiaryList(tAppDiary);
    }

    /**
     * 新增心岛日志
     * 
     * @param tAppDiary 心岛日志
     * @return 结果
     */
    @Override
    public int insertTAppDiary(TAppDiary tAppDiary)
    {

        if (tAppDiary.getDiaryId()!=null) {
            return tAppDiaryMapper.updateTAppDiary(tAppDiary);
        }
        tAppDiary.setCreateTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        tAppDiary.setUserId(AuthStorage.getUser().getId());
        return tAppDiaryMapper.insertTAppDiary(tAppDiary);
    }

    /**
     * 修改心岛日志
     * 
     * @param tAppDiary 心岛日志
     * @return 结果
     */
    @Override
    public int updateTAppDiary(TAppDiary tAppDiary)
    {
        return tAppDiaryMapper.updateTAppDiary(tAppDiary);
    }

    /**
     * 删除心岛日志对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteTAppDiaryByIds(String ids)
    {
        return tAppDiaryMapper.deleteTAppDiaryByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除心岛日志信息
     * 
     * @param diaryId 心岛日志ID
     * @return 结果
     */
    @Override
    public int deleteTAppDiaryById(Integer diaryId)
    {
        return tAppDiaryMapper.deleteTAppDiaryById(diaryId);
    }
}
